package cn.hanyx.coder.design.pattern.behavioral.chain.demo01;

/**
 * Handler
 *
 * @author hanyx
 * @date 2020/06/05
 */
public abstract class Handler {
    /**
     * 继承者Handler对象
     */
    protected Handler successor = null;

    /**
     * 设置继承者Handler
     *
     * @param successor
     */
    public void setSuccessor(Handler successor) {
        this.successor = successor;
    }

    protected abstract boolean doHandle();

    public final void handle() {
        if (!doHandle() && successor != null) {
            successor.handle();
        }
//        doHandle();
//        if (successor != null) {
//            successor.handle();
//        }
    }
}
